package com.android.baselibrary.thread

import android.os.Handler
import android.os.Looper


/**
 * @author: Mr.You
 * @create: 2023-10-27 15:04
 * @description:
 **/
object ThreadUtils {
    private val mHandler = Handler(Looper.getMainLooper())

    private val mThreadPoolExecutor = ThreadPoolManager.getInstance()

    fun <T> runMainThread(body: () -> T) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            body()
        } else {
            mHandler.post {
                body()
            }
        }
       // Thread {}.start()
    }
    fun <T> runChildThread(body:() -> T){
        mThreadPoolExecutor.addTask(body().hashCode().toString()) { body() }
    }
}